import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.ygqh.baby.po.YgLogistics;

public class VideoTools {

	public static void main(String[] args) throws Exception {

		// String regex = "(\\d{1,3}\\.){1,3}(\\d{1,3})";

		System.out.println(getHtml());
	}

	public static String getMatcher(String regex, String source) {
		String result = "";
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(source);
		while (matcher.find()) {
			result = matcher.group(1);
		}
		return result;
	}

	private static String getHtml() {
		String str = null;
		try {
			URL url = new URL("http://www.miaopai.com/show/IHaw-4xpCzVkdI9iQ-i2B~3EjpotY5yEfP1q1w__.htm");
			HttpURLConnection uc = (HttpURLConnection) url.openConnection();
			BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
			while ((str = br.readLine()) != null) {
				if (str.indexOf("videoSrc") != -1) {
					int startIndex = str.indexOf(":") + 2;
					int endIndex = str.indexOf("?");
					if (startIndex > 1 && endIndex > 0) {
						str = str.substring(startIndex, endIndex);
					}
					break;
				}
			}
			br.close();
			uc.disconnect();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str;
	}

	// 下载视频方法
	private static void getDondow(String url, String pathName) throws Exception {
		URL ul = new URL(url);
		HttpURLConnection conn = (HttpURLConnection) ul.openConnection();
		BufferedInputStream bi = new BufferedInputStream(conn.getInputStream());
		FileOutputStream bs = new FileOutputStream(pathName);
		System.out.println("文件大约：" + (conn.getContentLength() / 1024) + "K");
		byte[] by = new byte[1024];
		int len = 0;
		while ((len = bi.read(by)) != -1) {
			bs.write(by, 0, len);
		}
		bs.close();
		bi.close();
	}
}